package com.mymaxis.ebppx;
import com.checkfree.isolutions.customer.persist.*;
import com.checkfree.isolutions.statement.persist.*;

import java.util.*;

/**
 * Module Name  : EbppxEcsUser
 * Description  : The logon EcsUser holding the userId, email and accounts information
 * Last Updated : 2002-10-10
 *
 * @author lhlue
 *
 * Remarks :
 *
 */

 public class EbppxEcsUser{
	 private String userId;
	 private String email;
	 private String ipAddr;
	 private String merchantName;
	 private String msisdn;
	 private String sAccount;
	 private String mSegment;
	 private String statement = "";
	 private Vector vAccount = new Vector();
	 private Vector vOldAccount = new Vector();
	 private Vector vCfiAccounts = null;
	 private Map phoneMap = new HashMap();
	 private String accessType = ""; //P for pirncipal S for Supp
	 private String suppPhoneNo = "";
	 private String simNo = ""; //Added By Kha Yuen

	 public void setSimNo(String simNo){ //Added By Kha Yuen
		 this.simNo= simNo;
	 }
	 
	 public String getSimNo(){ //Added By Kha Yuen
		 return EbppxUtil.nullToEmpty(simNo);
	 }
	 
	 public void setUserId(String userId){
		 this.userId= userId;
	 }

	 public String getUserId(){
		 return EbppxUtil.nullToEmpty(userId);
	 }

	 public void setSAccount(String sAccount){
		 this.sAccount= sAccount;
	 }

	 public String getSAccount(){
		 return EbppxUtil.nullToEmpty(sAccount);
	 }
	 
	 public void setMSegment(String mSegment){
		 this.mSegment= mSegment;
	 }

	 public String getMSegment(){
		 return EbppxUtil.nullToEmpty(mSegment);
	 }

	 public void setMerchantName(String merchantName){
		 this.merchantName= merchantName;
	 }

	 public String getMerchantName(){
		 return EbppxUtil.nullToEmpty(merchantName);
	 }

	 public void setMsisdn(String msisdn){
		 this.msisdn= msisdn;
	 }

	 public String getMsisdn(){
		 return EbppxUtil.nullToEmpty(msisdn);
	 }

	 public void setEmail(String email){
		 this.email= email;
	 }

	 public String getEmail(){
		 return EbppxUtil.nullToEmpty(email);
	 }

	 public void setIPAddr(String ipAddr){
		 this.ipAddr= ipAddr;
	 }

	 public String getIPAddr(){
		 return EbppxUtil.nullToEmpty(ipAddr);
	 }
	 
	 public String getStatement()
		{
	  	    return EbppxUtil.nullToEmpty(statement);
		}

	 public void setStatement(String statement)
		{
			this.statement= statement;
		}

	 public void setAccount(String account){
		 if(account==null){
			 account = "";
		 }
		 vAccount.add(account);
	 }

	 public void clearAccount(){
		 vAccount.clear();
	 }

	 public void setPhoneNo(String phoneNo,String type){
		 if(phoneNo!=null){
			 phoneMap.put(phoneNo,type);
		 }
	 }

	 public void setAccessType(String accessType){
		 if(accessType!=null){
			 this.accessType = accessType;
		 }
	 }

	 public String getAccessType(){
		 return EbppxUtil.nullToEmpty(accessType);
	 }

	 public void setSuppPhoneNo(String suppPhoneNo){
		 if(suppPhoneNo!=null){
			 this.suppPhoneNo = suppPhoneNo;
		 }
	 }

	 public String getSuppPhoneNo(){
		 return EbppxUtil.nullToEmpty(suppPhoneNo);
	 }

	 public void setOldAccount(String oldAccount){
		 if(oldAccount==null){
			 oldAccount = "";
		 }
		 vOldAccount.add(oldAccount);
	 }

	 public String getAccount(int index){
		 return EbppxUtil.nullToEmpty((String) vAccount.elementAt(index));
	 }

	 public String getOldAccount(Vector newAcctVec, Vector oldAcctVec, String newAcctNo){
		 String element = "";
		 int index = newAcctVec.indexOf(newAcctNo);

		 if (index >= 0) {
			 element = (String)oldAcctVec.elementAt(index);
		 }
		 return EbppxUtil.nullToEmpty(element);
	 }

	 public String getOldAccount(int index){
		 return EbppxUtil.nullToEmpty((String) vOldAccount.elementAt(index));
	 }

	 public int getTotalAccounts(){
		 return vAccount.size();
	 }

	 public Vector getAccountExternalKeys(){
		 return vAccount;
	 }

	 public Vector getOldAccounts(){
		 return vOldAccount;
	 }

	 // return a vector of CFI Accounts
	 public Vector getAccounts() throws javax.ejb.FinderException, Throwable{
		 if (vCfiAccounts == null){
			 Vector cfiAccounts = new Vector();
			 Merchant cfiMerchant = MerchantHomeImpl.singleton().findByName(EbppxConstants.MERCHANT);
			 int size = vAccount.size();
             //Sytem.out.println("Size :"+size);
			 for (int i=0; i < size; i++){
				 Account account = AccountHomeImpl.singleton().findOrAutoCreateAccount((String)vAccount.elementAt(i), cfiMerchant);
				 account.setStatementRetention(372);

				 //if(account==null){
					 //account = AccountHomeImpl.singleton().findOrAutoCreateAccount((String)vAccount.elementAt(i), cfiMerchant);
					 //account = AccountHomeImpl.singleton().create((String)vAccount.elementAt(i), cfiMerchant);
					 //account.setStatementRetention(90,true);
				 //}
				 cfiAccounts.add(account);
			 }
			 vCfiAccounts = cfiAccounts;
			 return cfiAccounts;
		 }else{
			 return vCfiAccounts;
		 }
	 }
}

